package com.tanhua.controller;

import com.tanhua.domain.Question;
import com.tanhua.service.TanhuaService;
import com.tanhua.vo.NearUserVo;
import com.tanhua.vo.PageResult;
import com.tanhua.vo.RecommendUserVo;
import com.tanhua.vo.TodayBest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuController {

    @Autowired
    private TanhuaService tanhuaService;

    @GetMapping("/todayBest")
    public ResponseEntity<TodayBest> todayBest(){
        TodayBest tb = tanhuaService.todayBest();
        return ResponseEntity.ok(tb);
    }

    @GetMapping("/recommendation")
    public ResponseEntity<PageResult> recommendation(RecommendUserVo recommendUserVo){

        PageResult pr = tanhuaService.recommendation(recommendUserVo);
        return ResponseEntity.ok(pr);
    }

    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id")Long userId){
        TodayBest todayBest = tanhuaService.findPersonalInfo(userId);
        return ResponseEntity.ok(todayBest);
    }

    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        Question question = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(question.getTxt());
    }


    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map){
        Long toUserId = Long.valueOf(map.get("userId").toString());
        String reply = map.get("reply").toString();
        tanhuaService.replyQuestions(toUserId,reply);
        return ResponseEntity.ok(null);
    }


    @GetMapping("search")
    public ResponseEntity nearSearch(String gender,String distance){

        List<NearUserVo> list = tanhuaService.nearSearch(gender,distance);
        return ResponseEntity.ok(list);
    }



}
